"""
created  by  hzwlxy  at 2018/7/3 14:49
__author__: 西瓜哥
__QQ__ : 120235331
"""

__author__ = '西瓜哥'
from app.ext import db


class Base(db.Model):
    """
    __abstract__设置为True,不会创建Base表
    """
    __abstract__ = True

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="id")
    is_delete = db.Column(db.SmallInteger, index=True, default=0, nullable=False, comment="软删除，0未删除，1删除")
    _is_active = db.Column('is_active', db.SmallInteger, index=True, default=1, nullable=False, comment="状态")
    created_at = db.Column(db.DateTime, nullable=True, comment="创建时间")
    updated_at = db.Column(db.DateTime, nullable=True, comment="修改时间")


    def destroy(self):
        self.is_delete = 1

    def set_attrs(self, attrs):
        for key, value in attrs.items():
            if hasattr(self, key) and key != 'id':
                setattr(self, key, value)